/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.meanzoft.minecraft_clone.world;

import java.util.LinkedList;
import org.meanzoft.dragonways.client.Game;


/**
 *
 * @author Meanz
 */
public class BlockCompiler implements Runnable {

    private LinkedList<Chunk> work = new LinkedList<Chunk>();
    private boolean running = true;
    private static BlockCompiler blockCompiler;

    public static BlockCompiler getBlockCompiler() {
        return blockCompiler;
    }

    public BlockCompiler() {
        blockCompiler = this;
        new Thread(this).start();
    }

    public void add(Chunk c) {
        work.add(c);
    }

    public int getWorkSize() {
        return work.size();
    }

    public void run() {
        while (running) {
            try {
                if (!Game.gameRunning) {
                    running = false;
                }
                if (work.size() > 0) {
                    Chunk c = work.getFirst();

                    c.generateBlockData();

                    work.removeFirst();
                } else {

                    Thread.sleep(100);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
}
